import re
# 配置------------------------------------------------------------------------------------------------

f = open("../config.txt",encoding='utf-8')
config = f.read()
f.close()
  
replaceArr = [
    "outputName='[\w]+'",
    "tableName='[\w]+'",
    "keyName='[\w]+'",
]

configArr = [0]*3
for index, item in enumerate(replaceArr):
    first = re.findall(item, config)[0]
    second = re.findall("'[\w]+'",first)[0]
    configArr[index] = re.findall("[\w]+",second)[0]

# for i in configArr:
#     print(i)
# import sys
# sys.exit(0)

outputName = configArr[0]
tableName=configArr[1]
keyName = configArr[2]


#修改d_tmp_pw配置文件------------------------------------------------------------------------------------------
findArr = [
    "from [\w]+",
    "updatekeyinplace=no",
]

replaceArr = [
"from "+ tableName +" where "+keyName+" = :keyValue",
'updatekeyinplace=no arguments=(("keyValue", string))'
]

# for i in replaceArr:
#     print(i)
# import sys
# sys.exit(0)

f = open("../output/d_"+outputName+"_pw.srd",encoding='utf-16')
javaConfig = f.read()
f.close()


for index, item in enumerate(findArr):
    javaConfig = re.compile(item).sub(replaceArr[index], javaConfig)
f = open("../output/d_"+outputName+"_pw.srd",'w',encoding='utf-16')
f.write(javaConfig)
f.close()    
